#include <gtk/gtk.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>

#include "config.h"


/**
 * config_get_dir:
 *
 * Detect config directory by reading XDG_ variables.
 * If not, return $HOME/.config/gtk-speed-dial
 * Not creating directory here.
 *
 * Remark: returning value must be freed by call g_free()
 *
 * Return value: full path to config directory without trailing slash
 **/
gchar * config_get_dir ()
{
    const gchar * home;
    const gchar * xdg_config_home;


    home = g_getenv("HOME");

    if (!home)
        home = "/";


    xdg_config_home = g_getenv("XDG_CONFIG_HOME");

    if (!xdg_config_home)
        xdg_config_home = ".config";


    config.dir = g_strjoin(NULL, home, "/", xdg_config_home, "/gtk-speed-dial", NULL);

    return config.dir;
}


/**
 * config_create_dir:
 * @dir: directory path
 *
 * Create directory
 * Variables in path not supported.
 **/
void config_create_dir (const gchar * dir)
{
    // FIXME make it recursive
    g_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP);
}
